package com.clps.algorithm.chapter06.每日温度;

import java.util.Stack;

public class demo01 {
    public static void main(String[] args) {

    }

    public int[] dailyTemperatures(int[] temperatres){
        int[] result = new int[temperatres.length];
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < temperatres.length; i++) {
            while (!stack.empty() && temperatres[i] > temperatres[stack.peek()]){
                int prev = stack.pop();
                result[prev] = i - prev;
            }
            stack.push(i);
        }
        return  result;
    }
}
